<?php
/**
 * 摄影作品
 */
namespace app\index\controller;

use think\Controller;
use think\Request;

class Works extends Common
{   
    public function _initialize(){
        parent::_initialize();
        $child=$this->getchild(20);
        $this->assign([
            'child' =>$child,
        ]);
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index($id)
    {   
        if($id==null){
            $this->error("要访问的数据不存在！");
        }
        $res=db('article')->alias('a')
        ->join('pic p','p.aid=a.id')
        ->field('a.*,p.pic')
        ->where('a.cid',$id)
        ->paginate(5);
        $pos=$this->getPos($id);
        $catename=db('category')->where('id',$id)->field('cate_name,desc,keyword')->find();
        $this->assign([
            'res'=>$res,
            'currid'=>$id,
            'pos'=>$pos,
            'catename'=>$catename
        ]);
        return view();
    }

    /**
     * 详情
     *
     * @return \think\Response
     */
    public function show($id)
    {
        $article=db('article')->where('id',$id)->find();
        $pos=$this->getPos($article['cid']);
        $catename=db('category')->where('id',$article['cid'])->field('cate_name,desc,keyword')->find();
        $this->assign([
            'article'=>$article,
            'currid'=>$article['cid'],
            'pos'=>$pos,
            'catename'=>$catename
        ]);
        return view();
    }

 
}
